home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
MWCC03.ZIP
/
WINTASK.ZIP
/
WINTASK.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-08-18
|
18KB
|
555 lines
{**********************************************************************}
{* *}
{* Microworks Sample Application *}
{* *}
{* for Borland Pascal v7.0 and Turbo Pascal for Windows v1.5 *}
{* *}
{* Copyright 1992-93 Jeff Franks (Microworks) Sydney, Australia. *}
{* *}
{* You are free to use, modify, reproduce and distribute the *}
{* Sample Files (and/or any modified version) in any way you *}
{* find useful. *}
{* *}
{**********************************************************************}
{*** Introduction
Application := System Task List
Files := Wintask.exe, Wintask.pas, Wintask.res
Requires := MObjects and MWCC.dll
Purpose := Wintask shows you how to,
1. Use the EnumWindows function to set up a task list.
2. Set up an ownerdraw list box and fill it with icons.
3. Use some of the objects in the MWCC library.
Tabs := 2
Screen := 800 * 600
Date := August 1993.
Wintask is a Task Manager application that with a little work could be made into one
of the best task managers around. Its main purpose is to show you how to use an
ownerdraw list box and fill it with icons. Wintask also shows off some of the objects
in the MWCC library (a recessed list box, a recessed static control and the TMWCCButton
object).
I hope you find Wintask useful.
Jeff...
***}
program WinTask;
{$R WinTask.res}
uses WinTypes, WinProcs, ShellAPI, Strings, ToolHelp, MObjects,
{$IFDEF Ver15}
WObjects;
{$ELSE}
Objects, OWindows, ODialogs;
{$ENDIF}
const
{*** Button ID's ***}
idw_But1 = 201;
idw_But2 = 202;
idw_But3 = 203;
idw_But4 = 204;
idw_But5 = 205;
{*** Window Control ID's ***}
idw_Listbox = 401;
idw_Static = 402;
{*** Dialog Control ID's ***}
idd_Static1 = 403;
idd_Static2 = 404;
{*** System Menu ID ***}
idm_About = 701;
{*** Speaks for itself ***}
AppName : PChar = 'WinTask';
type
PAboutDialog = ^TAboutDialog;
TAboutDialog = object(TSFXDialog)
{***
TMWCCBmpButton is a BWCC style bitMap button object. TMWCCStatic is a static object
that displays either raised, recessed or normal static controls. WMDrawItem is required
to draw the TMWCCBmpButton ownerdraw button object.
***}
OkBut : PMWCCBmpButton;
Stat : PMWCCStatic;
constructor Init (AParent: PWindowsObject; AName: PChar);
procedure SetUpWindow; virtual;
procedure WMDrawItem (var Msg: TMessage); virtual wm_First + wm_DrawItem;
end;
PWinTaskWindow = ^TWinTaskWindow;
TWinTaskWindow = object(TSFXWindow)
{***
TSFXWindow is a resizable 3D Window object. It doesn't support normal menu's or
TScroller scroll bars. If you don't want the window to be resized set IsSizeable
in the constructor to False. For a resizeable window set it to True.
TMWCCListBox displays a recessed list box with a vertical scroll bar.
TMWCCButton is a button object that can be used to display a single bitmap, text,
or both on a button. If the button is resizeable as in this example the text
(or bitmap) automatically recentres itself. The button can either be raised or
recessed.
***}
LB : PMWCCListBox;
ST : PMWCCStatic;
TaskProc : TFarproc;
AppIcon, WinIcon, IcoHandle : HIcon;
But1, But2, But3, But4, But5 : PMWCCButton;
constructor Init(AParent: PWindowsObject; AName: PChar);
destructor Done; virtual;
function GetClassName : PChar; virtual;
procedure GetWindowClass (var AWndClass: TWndClass); virtual;
procedure SetUpWindow; virtual;
procedure WMSysCommand (var Msg: TMessage); virtual wm_First + wm_SysCommand ;
{*** WMMeasureItem and WMDrawItem draw the list box ***}
procedure WMMeasureItem (var Msg: TMessage); virtual wm_First + wm_MeasureItem;
procedure WMDrawItem (var Msg: TMessage); virtual wm_First + wm_DrawItem;
procedure WMSize (var Msg: TMessage); virtual wm_First + wm_Size;
procedure ListWindows; virtual;
procedure IDWListbox (var Msg: TMessage); virtual id_First + idw_ListBox;
procedure IDWBut1 (var Msg: TMessage); virtual id_First + idw_But1;
procedure IDWBut2 (var Msg: TMessage); virtual id_First + idw_But2;
procedure IDWBut3 (var Msg: TMessage); virtual id_First + idw_But3;
procedure IDWBut4 (var Msg: TMessage); virtual id_First + idw_But4;
procedure IDWBut5 (var Msg: TMessage); virtual id_First + idw_But5;
end;
PWinTaskApplication = ^TWinTaskApplication;
TWinTaskApplication = object(TApplication)
procedure InitMainWindow; virtual;
end;
var
IsTopWindows : Boolean;
{********** TWinTaskApplication **********}
procedure TWinTaskApplication.InitMainWindow;
{*** True produces a resizeable window ***}
begin
MainWindow := New(PWinTaskWindow, Init(nil, 'Task List'));
end;
{********** Callback function to list windows **********}
function GetTaskProc(Wnd: HWnd; LB: PMWCCListbox): Boolean; export;
{***
This is the function that actually enumerates all the windows. When the function name
is set to true the function continues to enumerate all the window giving you a handle
for each one (Wnd). Here I use the handle to get the window's title and add it to the
list box. If IsTopWindows is True only Top windows are listed. If its False all windows
are listed.
***}
var
Buf: array[0..79] of Char;
begin
GetTaskProc := True;
GetWindowText(Wnd, Buf, sizeof(Buf));
if (Buf[0] <> #0) and (StrIComp(Buf, 'Task List') <> 0) then
begin
if IsTopWindows then
if (GetWindow(Wnd, gw_Owner) = 0) then
LB^.AddString(Buf);
if not IsTopWindows then
LB^.AddString(Buf);
end;
end;
{********** TWinTaskWindow **********}
constructor TWinTaskWindow.Init (AParent: PWindowsObject; AName: PChar);
{***
The list box, static and button objects are initialized with zero values because
WMSize sets their position later.
***}
begin
TSFXWindow.Init(AParent, AName);
Attr.X := GetSystemMetrics(sm_CXScreen) div 4;
Attr.Y := (GetSystemMetrics(sm_CYScreen) div 4) + 5;
Attr.W := GetSystemMetrics(sm_CXScreen) div 2;
Attr.H := (GetSystemMetrics(sm_CYScreen) div 2) - 10;
LB := New(PMWCCListBox, Init(@Self, idw_ListBox, 0, 0, 0, 0, True));
{*** This sets the list box style to Ownerdraw, HasStrings and WantKeyboardInput ***}
LB^.Attr.Style := LB^.Attr.Style or lbs_OwnerDrawVariable or lbs_HasStrings
or lbs_WantKeyboardInput;
ST := New(PMWCCStatic, Init(@Self, idw_Static, '', 0, 0, 0, 0, 0, ctl_Recessed, False));
But1 := New(PMWCCButton, Init(@Self, idw_But1, 'All Windows', 0, 0, 0, 0, nil, 0));
But2 := New(PMWCCButton, Init(@Self, idw_But2, 'Top Windows', 0, 0, 0, 0, nil, 0));
But3 := New(PMWCCButton, Init(@Self, idw_But3, 'Show', 0, 0, 0, 0, nil, 0));
But4 := New(PMWCCButton, Init(@Self, idw_But4, 'Hide', 0, 0, 0, 0, nil, 0));
But5 := New(PMWCCButton, Init(@Self, idw_But5, 'End Task', 0, 0, 0, 0, nil, 0));
AppIcon := LoadIcon(HInstance, 'WinTask');
WinIcon := LoadIcon(HInstance, 'Windows');
{*** This sets IsTopWindows to true so that only top Windows are initially displayed ***}
IsTopWindows := True;
end;
destructor TWinTaskWindow.Done;
begin
DeleteObject(AppIcon);
DeleteObject(WinIcon);
TSFXWindow.Done;
end;
function TWinTaskWindow.GetClassName;
begin
GetClassName := AppName;
end;
procedure TWinTaskWindow.GetWindowClass (var AWndClass: TWndClass);
begin
TSFXWindow.GetWindowClass(AWndClass);
AWndClass.HIcon := AppIcon;
end;
procedure TWinTaskWindow.SetUpWindow;
var
SysMenu : HMenu;
begin
TSFXWindow.SetUp